package cn.wolfcode.trip.web.controller;

import cn.wolfcode.trip.base.domain.GoodsType;
import cn.wolfcode.trip.base.query.GoodsTypeQueryObject;
import cn.wolfcode.trip.base.service.IGoodsTypeService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Autowired
    private IGoodsTypeService goodsTypeService;


    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") GoodsTypeQueryObject qo) {
        PageInfo<GoodsType> pageInfo = goodsTypeService.selectForList(qo);
        model.addAttribute("result", pageInfo);
        return "goodsType/list";
    }


    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(GoodsType goodsType) {
        goodsTypeService.saveOrUpdate(goodsType);
        return "redirect:/goodsType/list.do";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id) {
        JSONResult result = new JSONResult();
        goodsTypeService.delete(id);
        return result;
    }
}
